package com.xiaojimao.Controller;

import com.xaiojimao.gr_common.dto.Result;
import com.xiaojimao.Pojo.Article;
import com.xiaojimao.Service.ArticleService;
import com.xiaojimao.Vo.ArticleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/article/article")
public class ArticleController {
    @Autowired
    ArticleService articleService;

    /**
     * 通用接口
     *
     * @param article
     * @return
     */
    @PostMapping("/update")
    public Result update(Article article) {
        return articleService.updateArticle(article);
    }

    /**
     * 获取文章列表
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public Result list(Integer pageNum, Integer pageSize) {
        return articleService.getArticleList(pageNum, pageSize);
    }

    /**
     * 创建文章
     *
     * @param article
     * @return
     */
    @PostMapping("/createArticle")
    public Result createArticle(@RequestBody ArticleVo article) {
        return articleService.createArticle(article);
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Long id) {
        return articleService.getByArticleId(id);
    }

    @GetMapping("/read")
    public Result read(String articleId, String userId) {
        return articleService.userReadHistory(articleId,userId);
    }
}
